package lgs

import (
	"fmt"
)

//单例模式

func Print(prefix string, level int, s ...interface{}) {
	fmt.Println(newWrite(prefix, level, s...))
}

//打印错误,有错误才打印
func PrintErr(err error) bool {
	if err != nil {
		Log.Err(err.Error())
	}
	return err != nil
}

//把错误写入文件
func WriteErr(err error) {
	if err != nil {
		w := newWrite(PErr, 3, err.Error())
		Log.Write(PErr, w.data())
	}
}

//把字符串写入文件
func WriteString(s string) {
	Log.Write(PErr, newWrite(PErr, 3, s).data())
}

//打印错误并写入文件
func PrintWriteErr(err error) {
	if err != nil {
		w := newWrite(PErr, 3, err.Error())
		fmt.Println(w)
		Log.Write(PErr, w.data())
	}
}

//自定义格式
//@prefix,前缀
//@level.层级
//@s,内容
func NewWrite(prefix string, level int, s ...interface{}) *IWrite {
	return newWrite(prefix, level, s...)
}

//-----------------------------------------------

func Test(s ...interface{})                 { Log.Test(s...) }
func Testf(format string, s ...interface{}) { Test(fmt.Sprintf(format, s...)) }

func Error(s ...interface{})                 { Log.Err(s...) }
func Err(s ...interface{})                   { Log.Err(s...) }
func Errorf(format string, s ...interface{}) { Log.Err(fmt.Printf(format, s...)) }
func Errf(format string, s ...interface{})   { Log.Err(fmt.Printf(format, s...)) }

func Info(s ...interface{})                 { Log.Info(s...) }
func Infof(format string, s ...interface{}) { Log.Info(fmt.Printf(format, s...)) }

func Debug(s ...interface{})                 { Log.Debug(s...) }
func Debugf(format string, s ...interface{}) { Log.Debug(fmt.Printf(format, s...)) }

//-----------------------------------------------

//func Template(prefix string, tier int, s ...interface{}) {
//	template(prefix, 0, tier, s...)
//}
//
////输出模板
//func template(prefix string, color, tier int, s ...interface{}) {
//	l := log.New(os.Stdout, "["+prefix+"] ", log.Ldate|log.Ltime|log.Lshortfile)
//	// kernel32 := syscall.NewLazyDLL("kernel32.dll")
//	// proc := kernel32.NewProc("SetConsoleTextAttribute")
//	// handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(color))
//	l.Output(tier, fmt.Sprintln(s...))
//	// handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(7))
//	// CloseHandle := kernel32.NewProc("CloseHandle")
//	// CloseHandle.Call(handle)
//}
